// hyb_yl/doctorHome/pages/result_task/result_task.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    keyword: "",
    tab_index: 1,
    x: '750rpx',
    y: "120rpx",
    duration: 600,
    keyword: "",
    status: "",
    star_time: "",
    end_time: "",
    label_id: "",
    page: 0,
    follow_id: "",
    list: [],
    fankui: false,
    zid: "",
    f_id: "",
    content: "",
    j_id: "",
  },

  daibantime: function (e) {
    console.log(e.detail.value)
    this.setData({
      daibantext: e.detail.value
    })
  },
  caiyustartime: function (e) {
    this.setData({
      star_time: e.detail.value
    })
  },
  caiyuendtime: function (e) {
    this.setData({
      end_time: e.detail.value
    })
  },
  tab_btn: function (e) {
    var index = e.currentTarget.dataset.index;
    this.setData({
      tab_index: index,
      status:e.currentTarget.dataset.status
    })
    this.setData({
      list:[],
      page:0,
    })
    this.getSuifang();

  },
  // 查看随访详情
  todetail: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var zid = e.currentTarget.dataset.zid;
    var j_id = e.currentTarget.dataset.j_id;
    var names = e.currentTarget.dataset.names;
    var sex = e.currentTarget.dataset.sex;
    var age = e.currentTarget.dataset.age;
    var u_thumb = e.currentTarget.dataset.u_thumb;
    var type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '/hyb_yl/doctorHome/pages/time_axis/time_axis?id=' + id+'&zid='+zid+'&j_id='+j_id+'&names='+names+'&sex='+sex+'&age='+age+'&u_thumb='+u_thumb+'&type='+type,
    })
  },
  onClickOverlay: function () {
    this.setData({
      show: false
    })
  },
  // 选择随访计划
  changefollow: function (e) {
    this.setData({
      follow_id: e.currentTarget.dataset.id
    })
  },
  // 修改关键词
  changenames: function (e) {
    this.setData({
      keyword: e.detail.value
    })
  },
  // 选择随访状态
  changestatus: function (e) {
    var that = this;
    that.setData({
      status: e.currentTarget.dataset.status
    })
  },
  // 选择标签
  changelabel: function (e) {
    this.setData({
      label_id: e.currentTarget.dataset.id
    })
  },
  // 点击筛选
  screen_btn: function (e) {
    this.setData({
      show: true
    })
  },
  exit() {
    var that = this
    this.setData({
      keyword: "",
      status: '',
      start_time: "",
      end_time: "",
      label_id: "",
      follow_id: "",
      show: false,
      page: 0,
      list: []
    })
    that.getSuifang();
    // wx.navigateBack()
  },
  confirm: function () {
    this.setData({
      page: 0,
      show: false,
      list: []
    })
    this.getSuifang();
  },
  // 筛选拖动
  movable: function (e) {
    console.log(e)
    this.setData({
      movable_x: e.detail.x,
      y: e.detail.y,
      movable_state: "touch",
    })
    console.log(this.data.x)
    console.log(this.data.windowWidth)
    if (this.data.x == 0) {
      this.setData({
        movable_state: "left",
      })
    } else if (this.data.x == this.data.windowWidth) {
      this.setData({
        movable_state: "right",
      })
    }
  },
  // 判断松手后的位置
  movableend: function (e) {
    console.log(e)
    var movable_x = this.data.movable_x
    if (movable_x <= 137) {
      this.setData({
        x: '0',
        movable_state: "left",
      })
    } else {
      this.setData({
        x: this.data.windowWidth,
        movable_state: "right",
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    // 获取手机宽度
    wx.getSystemInfo({
      success: (result) => {
        console.log(result)
        that.setData({
          windowWidth: result.windowWidth
        })
      },
    })
    
    that.getSuifang();
    that.getLabel();
    that.getFollow();
  },
  getSuifang: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/follow.zhuanjia_suifangs",
      data: {
        openid: wx.getStorageSync('openid'),
        page: that.data.page,
        keyword: that.data.keyword,
        status: that.data.status,
        start_time: that.data.star_time,
        end_time: that.data.end_time,
        label_id: that.data.label_id,
        follow_id: that.data.follow_id
      },
      success: function (res) {
        that.setData({
          list: that.data.list.concat(res.data),
          page: that.data.page + 1
        })
      }
    })

  },
  getFollow: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/follow.follow_lists",
      success: function (res) {
        that.setData({
          follow_list: res.data
        })
      }
    })
  },
  getLabel: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/follow.label",
      success: function (res) {
        that.setData({
          label_arr: res.data
        })
      }
    })
  },
  // 随访反馈
  suifang: function (e) {
    var that = this;
    that.setData({
      f_id: e.currentTarget.dataset.id,
      f_id: e.currentTarget.dataset.id,
      openid: e.currentTarget.dataset.openid,
      j_id: e.currentTarget.dataset.j_id,
      zid:e.currentTarget.dataset.zid,
      fankui: true,
    })
  },
  // 随访反馈内容
  bindinput(e) {
    this.setData({
      content: e.detail.value
    })
  },
  // 确定
  queding() {
    var that = this
    console.log("提交随访内容", that.data.content)
    app.util.request({
      'url': "entry/wxapp/follow.add_feedback",
      data: {
        openid: that.data.openid,
        zid: that.data.zid,
        f_id: that.data.f_id,
        content: that.data.content,
        j_id: that.data.j_id,
      },
      success: function (res) {
        that.setData({
          fankui: false,
        })
      }
    })

  },
  // 取消
  closezhe() {
    this.setData({
      fankui: false
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})